/* Lab06 Task 01, Jimmy Manone
 * main.c
 */

#include	<stdint.h>
#include	<stdbool.h>
#include	"utils/ustdlib.h"
#include	"inc/hw_types.h"
#include	"inc/hw_memmap.h"
#include	"driverlib/sysctl.h"
#include	"driverlib/pin_map.h"
#include	"driverlib/debug.h"
#include	"driverlib/hibernate.h" //macros, defines for low power modes
#include	"driverlib/gpio.h"


#ifdef	DEBUG
void__error__(char	*pcFilename,	uint32_t	ui32Line)
{
}
#endif




int main(void) {
	
	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
	//Configure clock at 40MHz

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Enable PF output
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
	//Choose Port F's outputs on pins 1, 2, 3
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x08);
	//Green LED (Pin1=2=red, Pin2=4=blue, Pin3=8=green)

	SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE); //Enable hibernation
	HibernateEnableExpClk(SysCtlClockGet());
	//Define clock supplied by hibernation module
	HibernateGPIORetentionEnable();
	//main GPIO pin state during hibernation/maintain on wake
	SysCtlDelay(64000000);
	//4 second delay

	//Configure RTC wakeup parameters
	HibernateRTCSet(0); //reset RTC to 0
	HibernateRTCEnable(); //turn on RTC
	HibernateRTCMatchSet(0,5); //set wakeup time for 5 sec in the future

	HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC);
	//wake condition on wakepin or rtc

	//HibernateWakeSet(HIBERNATE_WAKE_PIN);
	//wake condition on wake pin
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_3, 0x00);
	//Turn off green LED before unit goes to sleep


	HibernateRequest(); //Places unit into hibernation mode
	while(1) //Trap pending other peripheral interactions/activities
	{
	}


	return 0;
}
